package users

import (
	"svntool/application/controllers"
	"svntool/application/models/user"
	"svntool/application/models/linetool/reg"
	"svntool/application/models/linetool/reg/svn"
)

type AccountController struct {
	controllers.BaseController
}

//登陆
func (this *AccountController) Login() {
	user_model := user.Account{}
	result, err := user_model.Login(this.Ctx)
	if err != nil {
		this.Data["json"] = controllers.BuildJson(1001, err.Error(), "")
		this.ServeJSON()
		return
	}
	this.Data["json"] = controllers.BuildJson(200, "登录成功", &result)
	this.ServeJSON()
}

//注册
func (this *AccountController) Register() {
	//用户模型
	user_model := new(user.Account)
	//版本管理工具模型
	svn_model := new(svn.SvnReg)
	//上线工具模型
	linetool_account := reg.Role_account{user_model, svn_model}
	result, err := linetool_account.Register(this.Ctx)
	if err != nil {
		this.Data["json"] = controllers.BuildJson(1001, err.Error(), "")
		this.ServeJSON()
		return
	}
	this.Data["json"] = controllers.BuildJson(200, "登录成功", &result)
	this.ServeJSON()
}

//退出
func (this *AccountController) Logout() {
	user_model := user.Account{}
	user_model.Logout(this.Ctx)
}
